import client.WsClient;
import com.alibaba.fastjson.JSONObject;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import io.netty.util.concurrent.DefaultPromise;
import lombok.extern.slf4j.Slf4j;
import model.Message;
import server.ThirdClient;

import java.util.concurrent.TimeUnit;

/**
 * @author yujie
 * @createTime 2023/1/23 17:48
 * @description
 */
@Slf4j
public class tests {

    public static void main(String[] args) throws InterruptedException {
        Message message = new Message("client_req", "羊是什么意思");
        Channel channel = new WsClient().getClient();
        String json = JSONObject.toJSONString(message);
        DefaultPromise<Object> promise = new DefaultPromise<>(channel.eventLoop());
        try {
            channel.writeAndFlush(new TextWebSocketFrame(json)).sync();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        ThirdClient.map.put("WAIT_REP", promise);
        try {
            //等待2分钟
            promise.await(2, TimeUnit.MINUTES);
        } catch (InterruptedException e) {
            log.error("响应异常：{}", e.getClass(), e);
        }

    }

}
